package ui.control;

import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.ISelectionListener;
import org.eclipse.ui.IWorkbenchPart;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import ui.util.CalendarUtil;

import com.swtxml.swt.byid.ById;
import com.swtxml.views.SwtXmlViewPart;

import dao.EgnProduct;

public class ProductInfoViewTemp extends SwtXmlViewPart implements ISelectionListener {
	private final static Logger logger = LoggerFactory
			.getLogger(ProductInfoViewTemp.class);

	@ById
	private Text prodId;
	@ById
	private Text prodType;
	@ById
	private Text issueDate;
	@ById
	private Text matDate;

	@Override
	public void setupView() {
		getViewSite().getPage().addSelectionListener(this);
	}
	
	@Override
	public void selectionChanged(IWorkbenchPart part, ISelection selection) {
		if (selection instanceof IStructuredSelection) {
			Object first = ((IStructuredSelection) selection).getFirstElement();
			if (first instanceof EgnProduct) {
				
				EgnProduct prod = (EgnProduct) first;
				prodId.setText(prod.getProductId());
				prodType.setText(prod.getProductType());
				issueDate.setText(CalendarUtil.toString(prod.getIssueDate()));
				matDate.setText(CalendarUtil.toString(prod.getMaturityDate()));

			}
		}
	}
}
